File size: 7,953 Bytes
b1d4203
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Clips: ['1.mp4', '1.mp4']\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "['1.mp4', '1.mp4']"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "files = {\n",
    "    1: \"1.mp4\", 2: \"2.mp4\", 3: \"3.mp4\", 4: \"4.mp4\", 5: \"5.mp4\",\n",
    "    6: \"6.mp4\", 7: \"7.mp4\", 8: \"8.mp4\", 9: \"9.mp4\",\n",
    "    10: \"10.mp4\", 11: \"11.mp4\", 12: \"12.mp4\", 13: \"13.mp4\", 14: \"14.mp4\",\n",
    "    15: \"15.mp4\", 16: \"16.mp4\", 17: \"17.mp4\", 18: \"18.mp4\", 19: \"19.mp4\",\n",
    "    20: \"20.mp4\", 30: \"30.mp4\", 40: \"40.mp4\", 50: \"50.mp4\", \n",
    "    60: \"60.mp4\", 70: \"70.mp4\", 80: \"80.mp4\", 90: \"90.mp4\",\n",
    "    100: \"100.mp4\", 1000: \"1000.mp4\",\n",
    "    100000: \"100000.mp4\"\n",
    "}\n",
    "\n",
    "def get_clips(number):\n",
    "    num_digits = len(str(number))\n",
    "    place_values = []\n",
    "    place = 1\n",
    "\n",
    "    # Split number into place values\n",
    "    while number > 0:\n",
    "        digit = number % 10\n",
    "        if digit > 0:\n",
    "            place_values.append((digit, place))\n",
    "        number //= 10\n",
    "        place *= 10\n",
    "    \n",
    "    place_values.reverse()  # To process from the highest place value\n",
    "    clips = []\n",
    "    i = 0\n",
    "\n",
    "    while i < len(place_values):\n",
    "        digit, place = place_values[i]\n",
    "\n",
    "        # Handle cases for 1-20 at specific positions\n",
    "        if place == 1 and i > 0 and place_values[i - 1][1] == 10:  # Check for numbers ending in 1-20\n",
    "            combined = place_values[i - 1][0] * 10 + digit\n",
    "            if 1 <= combined <= 20:\n",
    "                clips.pop()  # Remove the previous 10's place clip\n",
    "                clips.append(files[combined])\n",
    "                i += 1\n",
    "                continue\n",
    "        \n",
    "        if place == 10 and digit * 10 <= 20:  # Numbers between 1-20 at higher positions\n",
    "            if i + 1 < len(place_values) and place_values[i + 1][1] == 1:\n",
    "                combined = digit * 10 + place_values[i + 1][0]\n",
    "                if 1 <= combined <= 20:\n",
    "                    clips.append(files[combined])\n",
    "                    i += 2\n",
    "                    continue\n",
    "\n",
    "        # Add individual clips\n",
    "        if digit in files:\n",
    "            clips.append(files[digit])\n",
    "        if digit * place in files:\n",
    "            clips.append(files[digit * place])\n",
    "\n",
    "        i += 1\n",
    "\n",
    "    # Handle 10,000 and 10,00,000 special cases\n",
    "    if len(place_values) % 2 == 1 and place_values[0][1] in [10000, 100000]:\n",
    "        first_digit = place_values[0][0]\n",
    "        if 1 <= first_digit <= 20:\n",
    "            clips.insert(0, files[first_digit])\n",
    "        elif first_digit * 10 in files:\n",
    "            clips.insert(0, files[first_digit * 10])\n",
    "        place_values = place_values[1:]\n",
    "\n",
    "    print(\"Clips:\", clips)\n",
    "    return clips\n",
    "\n",
    "# Example usage\n",
    "number = int(input(\"Enter a number: \"))\n",
    "get_clips(number)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "99: ['90.mp4', '9.mp4']\n",
      "111: ['1.mp4', '100.mp4', '11.mp4']\n",
      "256: ['2.mp4', '100.mp4', '50.mp4', '6.mp4']\n",
      "1000: ['1.mp4', '1000.mp4']\n",
      "1011: ['1.mp4', '1000.mp4', '11.mp4']\n",
      "9999: ['9.mp4', '1000.mp4', '9.mp4', '100.mp4', '90.mp4', '9.mp4']\n",
      "10000: ['10.mp4', '1000.mp4']\n",
      "24256: ['20.mp4', '4.mp4', '1000.mp4', '2.mp4', '100.mp4', '50.mp4', '6.mp4']\n",
      "22: ['20.mp4', '2.mp4']\n",
      "19: ['19.mp4']\n",
      "4: ['4.mp4']\n"
     ]
    }
   ],
   "source": [
    "files = {\n",
    "    1: \"1.mp4\", 2: \"2.mp4\", 3: \"3.mp4\", 4: \"4.mp4\", 5: \"5.mp4\",\n",
    "    6: \"6.mp4\", 7: \"7.mp4\", 8: \"8.mp4\", 9: \"9.mp4\",\n",
    "    10: \"10.mp4\", 11: \"11.mp4\", 12: \"12.mp4\", 13: \"13.mp4\", 14: \"14.mp4\",\n",
    "    15: \"15.mp4\", 16: \"16.mp4\", 17: \"17.mp4\", 18: \"18.mp4\", 19: \"19.mp4\",\n",
    "    20: \"20.mp4\", 30: \"30.mp4\", 40: \"40.mp4\", 50: \"50.mp4\",\n",
    "    60: \"60.mp4\", 70: \"70.mp4\", 80: \"80.mp4\", 90: \"90.mp4\",\n",
    "    100: \"100.mp4\", 1000: \"1000.mp4\",\n",
    "    100000: \"100000.mp4\"\n",
    "}\n",
    "\n",
    "def number_to_clips(n):\n",
    "    components = []\n",
    "    if n >= 100000:\n",
    "        lakh = n // 100000\n",
    "        if lakh > 0:\n",
    "            components.append(lakh)\n",
    "            components.append(100000)\n",
    "        n %= 100000\n",
    "    if n >= 1000:\n",
    "        thousand = n // 1000\n",
    "        if thousand > 0:\n",
    "            components.append(thousand)\n",
    "            components.append(1000)\n",
    "        n %= 1000\n",
    "    if n >= 100:\n",
    "        hundred = n // 100\n",
    "        if hundred > 0:\n",
    "            components.append(hundred)\n",
    "            components.append(100)\n",
    "        n %= 100\n",
    "    if n > 20:\n",
    "        tens = (n // 10) * 10\n",
    "        if tens > 0:\n",
    "            components.append(tens)\n",
    "        n %= 10\n",
    "    if n > 0:\n",
    "        components.append(n)\n",
    "    return components\n",
    "\n",
    "def generate_clip_sequence(n):\n",
    "    components = number_to_clips(n)\n",
    "    clip_sequence = []\n",
    "    for component in components:\n",
    "        if component in files:\n",
    "            clip_sequence.append(files[component])\n",
    "        else:\n",
    "            # Break down further if component is not in files\n",
    "            sub_components = number_to_clips(component)\n",
    "            clip_sequence.extend([files[sub] for sub in sub_components])\n",
    "    return clip_sequence\n",
    "\n",
    "# Example usage\n",
    "examples = [99, 111, 256, 1000, 1011, 9999, 10000, 24256, 22, 19, 4]\n",
    "for example in examples:\n",
    "    print(f\"{example}: {generate_clip_sequence(example)}\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "# code to remove first few and last few frames of clips using moviepy\n",
    "import os\n",
    "from moviepy.editor import VideoFileClip\n",
    "\n",
    "def trim_clips(clips, start=0, end=0):\n",
    "    trimmed_clips = []\n",
    "    for clip in clips:\n",
    "        clip_path = os.path.join(\"clips\", clip)\n",
    "        video = VideoFileClip(clip_path)\n",
    "        trimmed = video.subclip(start, video.duration - end)\n",
    "        trimmed_clips.append(trimmed)\n",
    "    return trimmed_clips\n",
    "\n",
    "# Example usage\n",
    "clips = os.listdir(\"clips\")\n",
    "clips = [clip for clip in clips if clip.endswith(\".mp4\")]\n",
    "\n",
    "# Trim first 1 second and last 2 seconds\n",
    "trimmed_clips = trim_clips(clips, 0.3, 0.3)\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "venv",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}