From 921a5f941622b8d66e2866d03c405afe233196a4 Mon Sep 17 00:00:00 2001 From: Simounet Date: Wed, 29 Jan 2014 18:45:21 +0100 Subject: [PATCH 1/2] Import Souncloud tracks uploaded date and tags - Handle created_at field from Soundcloud's tracks import so they can be at the right position in the timeline - Function to parse the tag_list field from the Soundcloud API - Add a created_at field to the soundcloud_data table - Var DATABASE_VERSION from index.php updated --- index.php | 2 +- .../soundcloud/models/SoundcloudModel.php | 27 +++++++++++++++---- .../update/006/alter_soundcloud_table.sql | 1 + 3 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 protected/install/database/update/006/alter_soundcloud_table.sql diff --git a/index.php b/index.php index 968aad7..4e06d24 100644 --- a/index.php +++ b/index.php @@ -1,6 +1,6 @@ id; + $data["track_id"] = @$item->id; + $data["created_at"] = @$item->created_at; $data["title"] = @$item->title; $data["artwork_url"] = @$item->artwork_url; $data["permalink_url"] = @$item->permalink_url; $data["stream_url"] = @$item->stream_url; - $data["uri"] = @$item->uri; + $data["uri"] = @$item->uri; + + $tags = $this->getTags((string) $item->tag_list); - $id = $this->addItem($data, $timestamp, SourceItem::AUDIO_TYPE, array(), false, false, $data['title']); + $id = $this->addItem($data, strtotime($data["created_at"]), SourceItem::AUDIO_TYPE, $tags, false, false, $data['title']); if ($id) $result[] = $id; } return $result; } + + private function getTags($tag_list) { + $matches = array(); + + // Get the words grouped between quotes (ex: "Manu Chao") + preg_match_all('~(["\'])([^"\']+)\1~', $tag_list, $quoted); + + // Get the others + $unescaped = trim(str_replace($quoted[0], "", $tag_list)); + $unescaped = preg_replace('/(\s)+/', ' ', $unescaped); + + $matches = array_merge((array)$quoted[2], (array)explode( ' ', $unescaped )); + + unset($quoted, $unescaped); + return count($matches) > 0 ? $matches : array(); + } private function lookupUserid($username) { diff --git a/protected/install/database/update/006/alter_soundcloud_table.sql b/protected/install/database/update/006/alter_soundcloud_table.sql new file mode 100644 index 0000000..0be3357 --- /dev/null +++ b/protected/install/database/update/006/alter_soundcloud_table.sql @@ -0,0 +1 @@ +ALTER TABLE soundcloud_data ADD `created_at` datetime NOT NULL after `description`; From d71d9720bd13bda0d1f276374cd249fb4e5ce227 Mon Sep 17 00:00:00 2001 From: Simounet Date: Wed, 5 Nov 2014 18:44:19 +0100 Subject: [PATCH 2/2] Revert "Import Souncloud tracks uploaded date and tags" This reverts commit 921a5f941622b8d66e2866d03c405afe233196a4. Revert created_at date handling for SoundClound favorites imported tracks because SoundCloud API doesn't provide the date for favorite action at the moment. Tracks were imported with it creation date on SoundCloud and not with the user favorite action date. --- index.php | 2 +- .../soundcloud/models/SoundcloudModel.php | 23 ++++--------------- .../update/006/alter_soundcloud_table.sql | 1 - 3 files changed, 5 insertions(+), 21 deletions(-) delete mode 100644 protected/install/database/update/006/alter_soundcloud_table.sql diff --git a/index.php b/index.php index 4e06d24..968aad7 100644 --- a/index.php +++ b/index.php @@ -1,6 +1,6 @@ id; - $data["created_at"] = @$item->created_at; + $data["track_id"] = @$item->id; $data["title"] = @$item->title; $data["artwork_url"] = @$item->artwork_url; $data["permalink_url"] = @$item->permalink_url; @@ -112,29 +113,13 @@ private function addItems($items) { $tags = $this->getTags((string) $item->tag_list); - $id = $this->addItem($data, strtotime($data["created_at"]), SourceItem::AUDIO_TYPE, $tags, false, false, $data['title']); + $id = $this->addItem($data, strtotime($timestamp, SourceItem::AUDIO_TYPE, $tags, false, false, $data['title']); if ($id) $result[] = $id; } return $result; } - - private function getTags($tag_list) { - $matches = array(); - - // Get the words grouped between quotes (ex: "Manu Chao") - preg_match_all('~(["\'])([^"\']+)\1~', $tag_list, $quoted); - - // Get the others - $unescaped = trim(str_replace($quoted[0], "", $tag_list)); - $unescaped = preg_replace('/(\s)+/', ' ', $unescaped); - - $matches = array_merge((array)$quoted[2], (array)explode( ' ', $unescaped )); - - unset($quoted, $unescaped); - return count($matches) > 0 ? $matches : array(); - } private function lookupUserid($username) { diff --git a/protected/install/database/update/006/alter_soundcloud_table.sql b/protected/install/database/update/006/alter_soundcloud_table.sql deleted file mode 100644 index 0be3357..0000000 --- a/protected/install/database/update/006/alter_soundcloud_table.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE soundcloud_data ADD `created_at` datetime NOT NULL after `description`;